package view
{
	import events.FarmClickEvent;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;

	public class Farm extends Sprite
	{
		/**
		 *空地 
		 */		
		private var farm:Loader;
		public function Farm(_url:String)
		{
			addFram(_url);
		}
		/**
		 *添加空地 
		 * @param _url
		 * 
		 */		
		private function addFram(_url:String):void
		{
			farm = new Loader();
			addChild(farm);
			farm.load(new URLRequest(_url));
			farm.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
			
		}
		/**
		 *图片加载完监听点击事件 
		 * @param event
		 * 
		 */		
		protected function loaderComplete(event:Event):void
		{
			farm.x = -farm.content.width*0.5;
			farm.y = -farm.content.height*0.5;
			farm.addEventListener(MouseEvent.CLICK,onClick);
		}
		/**
		 *点击事件
		 * 抛出事件 参数是 自己的坐标 
		 * @param event
		 * 
		 */		
		protected function onClick(event:MouseEvent):void
		{
			var evt:FarmClickEvent = new FarmClickEvent(FarmClickEvent.FARM_CLICKED,this,true);
			dispatchEvent(evt);
			
		}
	}
}